

public class Test11 {


    int count = 0;
    int rsum ;
    public int pathSum(TreeNode1 root, int sum) {
        rsum = sum;
        method( root , sum );
        return count ;
    }
    public void method(TreeNode1 root,int sum){
        if( root == null) return;
        if( root.val== sum ) count ++ ;
        if(root.left  != null){
            method( root.left ,sum - root.val);
            method(root.left ,rsum);
        }
        if(root.right != null){
            method( root.right,sum - root.val);
            method(root.right,rsum);
        }

    }
}
class TreeNode1 {

    int val;
    TreeNode1 left;
    TreeNode1 right;
    TreeNode1(int x) { val = x; }

}
